--
-- Author: ping.wang
-- Date: 2019-05-16 16:04:17
--
-- NewRankSecondTargetRender
--

local ClassRef = app.mvc.createRenderClass(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.NewRankSecondTargetRender))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.Panel:getContentSize() )
    self._ui["Panel/selected_btn"]:setTouchEnabled( false )
    self._ui["Panel/selected_btn"]:setSwallowTouches( false )
    self._ui["Panel"]:addTouchEventListener(function( sender, eventType )
        if eventType == ccui.TouchEventType.ended then
            self:setSelected( not self:isSelected() )
            executeFunc(self._onClick, self)
        end
    end)
    self:refresh()
end

function ClassRef:refresh()
    if self._data then
        local data = self._data
        self._ui.name:setString(L(data.rankConfig.name))

    end
end

function ClassRef:isSelected()
    return not self._ui["Panel/selected_btn"]:isBright()
end
function ClassRef:setSelected(b)
    if b then
        self._ui.name:setTextColor( cc.c3b( 255, 225, 132 ) )
    else
        self._ui.name:setTextColor( cc.c3b( 109, 109, 109 ) )
    end
    self._ui["Panel/selected_btn"]:setBright( not b )
end

function ClassRef:setClickHandler(func)
    self._onClick = func
end

return ClassRef
